<?php
include_once "header.php";

$cek_field="";
$sukses=0;
if (isset($_POST['ubahPassword'])){
  if ($_POST['password_baru']!="" || $_POST['password_baru2']!=""){
		$daftar_user = new Daftar_user();
		$user=new User();
		if($_POST['password_baru']==$_POST['password_baru2']){
			$user->setPassword($_POST['password_baru']); 
			$user->setNip($_SESSION['nip']);
			$daftar_user->editPassword($user);
			echo "<script>alert('Password berhasil diubah');</script>";
		}else{
			$cek_field="Peringatan: Password tidak cocok.";
		}
	} else {
		$cek_field="Peringatan: Silahkan isikan seluruh data yang tersedia.";
	}
		
}

?>

<div id="container">
	<div id="errorcont">
		<?php echo $cek_field;
		?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Beranda
			</div>
			<div id="body">
			<p>Silahkan Merubah Password anda untuk keamanan akses akun Anda.</p>
				 
			  <form name="form" method="post" action="ubah_password.php">
			  <input type="hidden" name="ubahPassword"/>
			  
			  <table border=0 cellspacing=0 cellpadding=4 width=100%>
			  <tr>
				<td width=20%>Password Baru</td>
				<td width=2%>:</td>
				<td><input type="password" name="password_baru" /></td>
			  </tr>
			  
			  <tr>
				<td>Konfirmasi Password Baru</td>
				<td>:</td>
				<td><input type="password" name="password_baru2"/></td>
			  </tr>
			  <tr>
				<td></td>
				<td></td>
				<td></td>
			  </tr>
			  
			  <tr>
				<td><input type="submit" value="Simpan" onclick="return cekField();"/></td>
				<td></td>
				<td></td>
			  </tr>
			  
			  </table>
				
			  </form>         
				
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>


<script type="text/javascript">
function cekField(){
	
		
		var pass1 = document.forms['form']['password_baru'].value;
		var pass2 = document.forms['form']['password_baru2'].value;
		
		
		
		if(pass1=="" || pass2==""){
			alert('Peringatan : Silahkan isikan seluruh data yang tersedia.');
			return false;
		}
		
		if(pass1!=pass2){
			alert('Peringatan : Password yang Anda input tidak cocok.');
			return false;
		}
		
}
	
</script>
